<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.js"></script>
<body>
<script>
promise_test(function(t) {
  var url = 'resources/stop-worker-with-pending-fetch.js';
  var scope = 'resources/stop-worker-with-pending-fetch-scope/';
  var registration;

  return service_worker_unregister_and_register(t, url, scope)
    .then(reg => {
        registration = reg;
        return wait_for_state(t, reg.installing, 'activated');
      })
    .then(_ => with_iframe(scope))
    .then(_ => internals.terminateServiceWorker(registration.active))
    .then(_ => with_iframe(scope))  // Check the sanity of the SW.
    .then(_ => service_worker_unregister(t, scope));
  }, 'Stopping SW with pending fetch event should not cause crash.');
</script>
</body>
